package com.mldong.modules.cms.controller;

import com.mldong.auth.Perm;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.cms.dto.ModelPageParam;
import com.mldong.modules.cms.dto.ModelParam;
import com.mldong.modules.cms.service.ModelService;
import com.mldong.modules.cms.vo.ModelVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 模型表 前端控制器
    * </p>
*
* @author mldong
* @since 2022-10-23
*/
@RestController
@Api(tags = "模型表管理")
@RequiredArgsConstructor
public class ModelController {
    private final ModelService modelService;
    /**
     * 添加模型表
     * @param param
     * @return
     */
    @PostMapping("/cms/model/save")
    @ApiOperation(value = "添加模型表")
    @Perm
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) ModelParam param) {
        modelService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除模型表
     * @param param
     * @return
     */
    @PostMapping("/cms/model/remove")
    @ApiOperation(value = "删除模型表")
    @Perm
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        modelService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改模型表
     * @param param
     * @return
     */
    @PostMapping("/cms/model/update")
    @ApiOperation(value = "修改模型表")
    @Perm
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) ModelParam param) {
        modelService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个模型表
     * @param param
     * @return
     */
    @PostMapping("/cms/model/detail")
    @ApiOperation(value = "查询单个模型表")
    @Perm
    public CommonResult<ModelVO> detail(@RequestBody IdParam param) {
        ModelVO model = modelService.findById(param.getId());
        return CommonResult.data(model);
    }
    /**
     *分页查询模型表列表
     * @param param
     * @return
     */
    @PostMapping("/cms/model/page")
    @ApiOperation(value = "分页查询模型表列表")
    @Perm
    public CommonResult<CommonPage<ModelVO>> page(@RequestBody ModelPageParam param) {
        return CommonResult.data(modelService.page(param));
    }
}
